<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: mapi_model_article.php 338 2013-04-27 08:06:38Z laoguozhang $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class stat_base_model extends dzf_base_model
{

	/**
	 * 处理下一页
	 * @param int $i
	 * @param int $limit
	 * @param int $start
	 * @return string
	 */
	protected function _current($i, $limit, $start) {
		if($i > $limit) {
			$current = (string)(($i - 1) + $start);
		} else {
			$current = '-1';
		}
		return $current;
	}

	/**
	 * 保留方法
	 * @param type $parameters
	 */
	protected function _init_parameters($parameters){

	}

	/**
	 * 处理limit的最大start和limit值
	 * @param int $start
	 * @param int $limit
	 * @return array
	 */
	public function max_start_limit($start, $limit) {
		if($start > 100000) {
			$start = 100000;
		}
		if ($limit > 10000) {
			$limit = 10000;
		}
		return array($start, $limit);
	}

	/**
	 * 取系统头像地址
	 * @param str $username:用户名
	 * @return 返回用户名md5值后两位的头像文件
	 */
	public function get_system_avatar($username) {
		$url = '';
		if($username) {
			$url = 'http://ugc.qpic.cn/dczmobile/10000/'.substr(strtolower(md5($username)), -2).'/0';
		}
		return $url;
	}

	/**
	 * 数据签名
	 * @param string $str 源数据
	 * @param int $length 返回值的长度，8-32位之间
	 * @return string
	 */
	public function dsign($str, $length = 16){
		return substr(md5($str.'35492dXAxu5OWUBe'), 0, ($length ? max(8, $length) : 16));
	}

	public function testuser() {
		static $member = array('83' => 1, '97' => 1, '3842' => 1, '1729' => 1, '1472' => 1, '3806' => 1, '143' => 1, '695' => 1, '107' => 1);
		return isset($member[DZF::app()->member['uid']]);
	}
	
	/*
	 * 通用调试程序
	 */
	public function debug($var = null, $vardump = false) {
		if(DZF::app()->member['uid'] == 83 || DZF::app()->member['uid'] == 97) {
			echo '<pre>';
			$vardump = empty($var) ? true : $vardump;
			if($vardump) {
				var_dump($var);
			} else {
				print_r($var);
			}
			exit();
		}
	}
}
